// 获取验证码
var reg = /^(\+?44|0)7\d{9}$/;
var numIsExist = '';
$('.get_code_btn').click(function () {
    var tel =  $('.tel').val();
    if ('' == tel){
        layer.msg('请输入手机号</br>Please enter the phone number',{
            skin:'winning-class',
            time:3000
        });
    }else {
        if (!checkTel(tel)) return false;
        $.ajax({
            type: "post",
            url: "/userweb/login/codeGet",
            cache: false,
            data: {account: tel,type:'register'},
            dataType: "json",
            success: function (data) {
                if(200 == data.status){
                    function invokeSettime(obj) {
                        var countdown = 60;
                        settime(obj);
                        function settime(obj) {
                            var text = '<div class="my_title_zh">获取验证码</div>' +
                                '<div class="my_title_en">Get the verify</div>';
                            if (countdown == 0) {
                                $(obj).attr("disabled",false);
                                $(obj).html(text);
                                countdown = 60;
                                return;
                            } else {
                                var html = '<div class="code_time">' +
                                    '<div class="code_time_s">'+ countdown +'S</div>' +
                                    '<div class="code_time_text">' +
                                    '<div>重新发送</div>' +
                                    '<div>Resend</div>' +
                                    '</div>' +
                                    '</div>';
                                $(obj).attr("disabled",true);
                                $(obj).html(html);
                                countdown--;
                            }
                            setTimeout(function() {
                                settime(obj);
                            },1000);
                        }

                    }
                    new invokeSettime('.get_code_btn');
                }
                numIsExist = data.numIsExist;
                layer.msg(data.msg,{
                    skin:'winning-class',
                    time:3000
                });
            }
        });
    }
});
//注册
$('.my_submit_btn').click(function () {
    var account =  $('.tel').val();
    localStorage.setItem('account',account);
    var password =  $('.pwd').val();
    var check =  $('.accept_checkbox').is(':checked');
    var code = $('.input_code').val();
    var invite = $('.invite').val();
    if (account){
        if (!checkTel(account)) return false;
        /*layer.msg('请输入正确的电话号码格式</br>Please enter the correct format of the phone number',{
                        skin:'winning-class',
                        time:3000
                    });
        return false;*/
    }
    if ('' == account){
        layer.msg('请输入手机号</br>Please enter the phone number',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else if ('' == code){
        layer.msg('请输入验证码</br>Please enter the verification code',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else if ('' ==password ){
        layer.msg('请输入密码</br>Please enter the password',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else  if(5>=password.length || 17<=password.length){
        layer.msg('请输入6-16位密码</br>Please enter 6-16 bit passwords',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else  if(true !== check){
        layer.msg('你还没有同意用户协议</br>You haven\'t agreed to the user agreement',{
            skin:'winning-class',
            time:3000
        });
        return false;
    }else {
        $.ajax({
            type: "post",
            url: "/userweb/login/registered",
            cache: false,
            data: {account: account,code: code,password: password,invite:invite},
            dataType: "json",
            success: function (data) {
                if (200 == data.status) {
                    layer.msg('注册成功</br>register was successful',{
                        skin:'winning-class',
                        time:3000
                    });
                    location.href = "/userweb/index/improveInfo";
                }else if (220 == data.status){
                    layer.msg('手机号已注册</br>The phone number has been registered',{
                        skin:'winning-class',
                        time:3000
                    });
                }else if (230 == data.status){
                    layer.msg('邀请码错误</br>Invitation code error',{
                        skin:'winning-class',
                        time:3000
                    });
                }else {
                    layer.msg('注册失败</br>register was failed',{
                        skin:'winning-class',
                        time:3000
                    });
                }
            }
        });
    }
});

$(function() {
    $.ajax({
        type: "post",
        url: "/userweb/Homepage/defaults",
        cache: false,
        data: {},
        dataType: "json",
        success: function (res) {
            if (200 == res.status) {
                var android_image = oss_url + res.xhlData.android_image;
                var ios_image = oss_url + res.xhlData.ios_image;
                // var html  = '<img src=' + image + ' alt="">';
                var html  = '<div class="code_img"><img src=' + android_image + ' alt="">'
                    +'<div class="code_title">Android</div>'
                    +'</div>'
                    +'<div class="code_img">'
                    +'<img src=' + ios_image + ' alt="">'
                    +'<div class="code_title">ios</div>'
                    +'</div>';
                var html1 = res.xhlData.user_content;
                $('.reg_code_img').html(html);
                $('.user_agreement_p').html(html1);
            }else {
                layer.msg('二维码获取失败',{
                    skin:'winning-class',
                    time:3000
                });
            }
        }
    });
});